package com.example.demo.entity;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.persistence.*;
import java.util.Collection;
import java.util.List;

/**
 * Copyright(C), 2020-2021, AmbroseCdMeng
 * FileName:    SysRole
 * Author:      AmbroseCdMeng
 * Date:        2021/3/4 10:24
 * Description: 角色实体
 * History:
 * <author>     <time>      <version>       <desc>
 * 作者姓名     修改时间        版本号           描述
 */
@Entity
@Data
public class SysRole implements UserDetails {
    /**
     * 主键。自动增长
     */
    @Id
    @GeneratedValue
    private long id;

    /**
     * 中文名
     */
    private String cnname;

    /**
     * 角色标识，如：管理员
     */
    private String role;

    /**
     * 角色描述。用于在 UI 界面显示角色相关描述信息
     */
    private String description;

    /**
     * 是否可用。
     */
    private Boolean enabled = Boolean.TRUE;

    /**
     * 角色 —— 权限 关系。多对多
     */
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "SysRolePermission", joinColumns = {@JoinColumn(name = "roleId")}, inverseJoinColumns = {@JoinColumn(name = "permissionId")})
    private List<SysPermission> permissions;

    /**
     * 用户 ——角色 关系。多对多
     */
    @ManyToMany
    @JoinTable(name = "SysUserRole", joinColumns = {@JoinColumn(name = "roleId")}, inverseJoinColumns = {@JoinColumn(name = "uid")})
    private List<SysUser> userInfos;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return null;
    }

    @Override
    public String getUsername() {
        return null;
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return false;
    }
}
